package daos;

import hibernate.HibernateUtil;
import java.util.List;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import negocio.ObraSocial;

public class ObraSocialDAO {

	private static ObraSocialDAO instancia = null;
	private static SessionFactory sf = null;

	public static ObraSocialDAO getInstancia(){
		if(instancia == null){
			sf = HibernateUtil.getSessionFactory();
			instancia = new ObraSocialDAO();
		} 
		return instancia;
	}
	
	public void guardarObraSocial(ObraSocial os){
		Session session = sf.openSession();
		session.beginTransaction();
		session.save(os);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public void eliminarObraSocial(ObraSocial os){
		Session session = sf.openSession();
		session.beginTransaction();
		session.delete(os);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	public void modificarObraSocial(ObraSocial os){
		Session session = sf.openSession();
		session.beginTransaction();
		session.update(os);
		session.flush();
		session.getTransaction().commit();
		session.close();
	}

	@SuppressWarnings("unchecked")
	public List<ObraSocial> obtenerObrasSociales(){
		Session session = sf.openSession();
		List<ObraSocial> obrasSociales = session.createQuery("from ObraSocial").list();
		session.close();
		return obrasSociales;
	}
}
